﻿using Cngot.Extensions.EventBus.Kafka;
using Cngot.Extensions.EventBus.Kafka.Integration;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace AspNetCore.WebApi.Consumer
{
    [MessageSubscribe("aaa", "aaa_group", "kafka", isDelay: true)]
    public class KafkaConsumerListener : IKafkaConsumerListener
    {
        private readonly ILogger<KafkaConsumerListener> _logger;

        public KafkaConsumerListener(ILogger<KafkaConsumerListener> logger)
        {
            _logger = logger;
        }

        public Task HandleAsync(RecieveResult recieveResult)
        {
            _logger.LogWarning("AAAKafkaConsumerListener:" + recieveResult.Message + ">>" + DateTime.Now);
            recieveResult.Commit();
            return Task.CompletedTask;
        }
    }

    [MessageSubscribe("aaa", "aaabbb_group", "kafka")]
    public class KafkabbbConsumerListener : IKafkaConsumerListener
    {
        private readonly ILogger<KafkaConsumerListener> _logger;

        public KafkabbbConsumerListener(ILogger<KafkaConsumerListener> logger)
        {
            _logger = logger;
        }

        public Task HandleAsync(RecieveResult recieveResult)
        {
            _logger.LogWarning("BBBKafkaConsumerListener:" + recieveResult.Message + ">>" + DateTime.Now);
            recieveResult.Commit();
            return Task.CompletedTask;
        }
    }
}
